class Upload {
    constructor (parms) {
        this.url = parms.url
    }
    img (url) {
        const vm = this
        return new Promise((resolve, reject) => {
            wx.chooseImage({
                success (res) {
                    let tempFilePaths = res.tempFilePaths
                    wx.uploadFile({
                        url: vm.url,
                        filePath: tempFilePaths[0],
                        name: 'imgFile',
                        success (res) {
                            if (res.statusCode === 200) {
                                resolve(JSON.parse(res.data))
                            } else {
                                reject(res)
                            }
                        },
                        fail () {
                            reject('上传失败到微信服务器失败')
                        }
                    })
                }
            })
        })
    }
}

module.exports = new Upload({
    url: 'http://uploadpic'
})
